<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

		<link href="../cssmui/mui.min.css" rel="stylesheet" />
		<script type="text/javascript" src="../hyl/core.js"></script>		
		<script type="text/javascript" src="../mui/common.js"></script>
		
		<script type="text/javascript" src="./designsql.js"></script>
		<script type="text/javascript" src="../hyl/core.mdl.js"></script>
		<script type="text/javascript" src="../hyl/plus/sqlite.web.js"></script>
		<script type="text/javascript" src="../hyl/omd.sql.js"></script>
		<script type="text/javascript" src="../mui/mui.min.js"></script>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">测试对象</h1>

		</header>
		<div class="mui-content">
			表
			<select id="select1" width="120px">
				<option value="">未选择</option>
			</select><br>			
			入参：<textarea id="text0" rows="2" cols="38"></textarea><br>
			条件：<input id="where0" /><br>
			sql：<textarea id="text1" rows="2" cols="38"></textarea><br>
			<button id="btnins">插入</button>
			<button id="btnupd">修改</button>
			<button id="btsave">保存</button>
			<button id="btsel">查询</button>
			<button id="btselo">查询对象</button>
			<button id="btselp">查询一页</button><br>
			输出：<textarea id="text2" rows="20" cols="38"></textarea><br>

		</div>
	
	</body>
</html>
		<script type="text/javascript">
			var _DB = new DataBase('mydb');
			//console.log(a);
				
			var oSel = document.getElementById("select1");
			var text0 = document.getElementById("text0");
			var text1 = document.getElementById("text1");
			var text2 = document.getElementById("text2");
			var where0 = document.getElementById("where0");
			
			var _Obj = null;
			for (var i in _DBconfig) {
				var oPt = new Option(_DBconfig[i].tablename,_DBconfig[i].tablename); //创建一个option
				oSel.add(oPt); //添加
			}
			
			oSel.addEventListener("change",function (){
				//console.log(oSel.selectedIndex)
				var tablename=oSel.options[oSel.selectedIndex].value;	
				//console.log(tablename)
				var Obj = new OObj(_DB,tablename);	
				Obj.getList(null,function(rs){
					if(rs.length>0)
						text0.value=JSON.stringify(rs);//[0]
				});
				
			})
		document.getElementById("btnins").addEventListener('click', function() {
			var tablename=oSel.options[oSel.selectedIndex].value;			
			var Obj = new OObj(_DB,tablename);	
			var p=JSON.parse(text0.value);
			Obj.add(p,function(rs,sql){
				text1.value	=sql
				text2.value	=JSON.stringify(rs)
			})
		});
		document.getElementById("btnupd").addEventListener('click', function() {
			var tablename=oSel.options[oSel.selectedIndex].value;			
			var Obj = new OObj(_DB,tablename);	
			var p=JSON.parse(text0.value);
			var w=where0.value;
			Obj.where(w).update(p,function(rs,sql){
				text1.value	=sql
				text2.value	=JSON.stringify(rs)
			})
		});
		document.getElementById("btsave").addEventListener('click', function() {
			var tablename=oSel.options[oSel.selectedIndex].value;			
			var Obj = new OObj(_DB,tablename);	
			var p=JSON.parse(text0.value);
			var w=where0.value;
			Obj.where(w).saveMap(p,function(rs,sql){
				text1.value	=sql
				text2.value	=JSON.stringify(rs)
			})
		});
		document.getElementById("btsel").addEventListener('click', function() {
			var tablename=oSel.options[oSel.selectedIndex].value;			
			var Obj = new OObj(_DB,tablename);	
			var w=where0.value;
			Obj.where(w).getList(null,function(rs,sql){
				text1.value	=sql
				text0.value	=JSON.stringify(rs)
			})
		});
		document.getElementById("btselp").addEventListener('click', function() {
			var tablename=oSel.options[oSel.selectedIndex].value;			
			var Obj = new OObj(_DB,tablename);			
			var w=where0.value;
			Obj.where(w).page({index:"order by id ",start:1,len:2}).getList(null,function(rs,sql){
				text1.value	=sql
				text0.value	=JSON.stringify(rs)
			})
		});
		document.getElementById("btselo").addEventListener('click', function() {
			var tablename=oSel.options[oSel.selectedIndex].value;			
			var Obj = new OObj(_DB,tablename);			
			var w=where0.value;
			Obj.where(w).page({len:1}).getMap(null,function(rs,sql){
				text1.value	=sql
				text0.value	=JSON.stringify(rs)
			})
		});
		</script>